import router from "@/router";
import useAccountStore from "@/store/accountModule";

export const setupGuard = () => {
    router.beforeEach((to, from) => {
        const accountStore = useAccountStore()
        const isLogin = accountStore.userInfo.id !== 0
        if (to.path !== "/login") {
            if (!isLogin) {
                return {
                    name: "Login"
                }
            }
        } else { // 要去login页面
            if (isLogin) {
                return {
                    name: "Home"
                }
            }
        }
    })
}